#!/usr/bin/env python
# -*- coding: utf-8 -*-

import fileinput

def test_kw_args(name, **kwargs):
    print(name)
    # print(type(kwargs))
    kwargs["a"][1] = 44
    for key, value in kwargs.items():
        print(key, value)
        
def func_count():
    def f(i):
        def g():
            return i * i
        return g
    
    # for i in range(1, 4):
    #     yield f(i)
    
    fs = []
    for i in range(1, 4):
        fs.append(f(i))
    return fs

# 尾递归:指在函数返回时调用函数本身，并且return语句不能包含表达式
def fact(n):
    return fact_iter(n, 1)

def fact_iter(n, prod=1):
    if n == 1:
        return prod
    return fact_iter(n - 1, n * prod)


class Student(object):
    def __init__(self, name, score):
        self.name = name
        self.score = score
        print("init")
    
    def print_score(self):
        print("%s: %s" % (self.name, self.score))
        
def test_fileinput():
    # with open("index.py", 'r', encoding="utf-8") as f:
    #     f.readline()
    # f.close()
    
    for line in fileinput.input("index.py", encoding="utf-8"):
        print(line)
        
    fileinput.close()
        
if __name__ == '__main__':
    # test_kw_args('test1', a=1, b=2, c=3)
    # kwargs = {"a":{1:11,2:22,3:33}, "b":2, "c":3}
    # test_kw_args('test2', **kwargs)
    # print(kwargs)
    
    # for f in func_count():
    #     print(f())
        
    # f1,f2,f3 = func_count()
    # print(type(f1))
    # print(f1, f2, f3)
    # print("f1:", f1())
    # print("f2:", f2())
    # print("f3:", f3())
    
    # print("fact(5):", fact(5))
    
    # a = 'hello'
    # print(type(a))
    # b = a.encode('utf-8')
    # print(type(b))
    # c = b.decode
    # pass
    test_fileinput()
    